package com.kingdee.pda.commonmethod;

import android.content.Context;

import com.example.basecommon.http.MyObserver;
import com.example.basecommon.http.RxHelper;
import com.example.basecommon.http.rxjava.BaseResponse;
import com.example.basecommon.http.rxjava.HttpUtils;
import com.example.basecommon.utils.ConstantUtil;
import com.kingdee.pda.Api;
import com.kingdee.pda.entity.SkuBindLocationsBean;

import java.util.HashMap;

/**
 * @author：dlj
 * @data：2022/1/14
 * @des sku绑定的移入库位查询 Presenter
 */
public class QuerySkuBindLocationPresenter {

    private Context context;
    private QuerySkuBindLocationView view;

    public QuerySkuBindLocationPresenter(Context context, QuerySkuBindLocationView queryStockView) {
        this.context = context;
        this.view = queryStockView;
    }

    //查询sku绑定的移入库位
    public void queryGoodsLocation(long warehouseId, String barcode) {
        HashMap<String, Object> json = new HashMap<>();
        json.put("warehouseId", warehouseId);
        json.put("itemBarcode", barcode);
        MyObserver<SkuBindLocationsBean> myObserver = new MyObserver<SkuBindLocationsBean>(context) {
            @Override
            public void onSuccess(BaseResponse<SkuBindLocationsBean> result) {
                view.queryGoodsLocationSuccess(result.data);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.queryGoodsLocationFailed(msg);
            }
        };
        HttpUtils.request(Api.class)
                .queryGoodsLocation(ConstantUtil.PDA_sku_bindlocation, json)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }
}
